<template>
  <div :class="className" :style="{height:height,width:width}"/>
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import { debounce } from '@/utils'

const animationDuration = 6000

export default {
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initChart()
    this.__resizeHandler = debounce(() => {
      if (this.chart) {
        this.chart.resize()
      }
    }, 100)
    window.addEventListener('resize', this.__resizeHandler)
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    window.removeEventListener('resize', this.__resizeHandler)
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        title: {
            text: '行业-企业性质',
            
        },
        color:['#f86c60','#d02a46'],
        legend: {

            data: ["总贷款余额", "不良贷款余额"],
            x:"right",
            y:"bottom",
            icon: "circle",  

            itemWidth: 10, 

            itemHeight: 10, 

            itemGap: 40 

        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow' 
          }
        },
        xAxis: [{
          type: 'category',
          
          data: ['农', '制造业', '建筑业', '交通 运输', '信息 传输','房地 产业','科学 研究','居民 服务','卫生',"公共 管理"].map(function(str){
              return str.replace(' ', '\n')
          }),
          axisTick: {
            alignWithLabel: true
          },
          axisLabel:{
              interval:0
          }
        }
        
        ],
        yAxis: [{
          type: 'value',
          axisTick: {
            show: false
          }
        }],
        series: [
            {   name: '总贷款余额',
                data: [50, 60, 60, 70, 70,50, 40, 50, 40, 60],
                type: 'line',
                smooth: 0,
                areaStyle: {},
                symbol: 'none',
                itemStyle : {  
                    normal : {  
                        lineStyle:{  
                            color:'#f86c60'  
                        }  
                    }  
                },
            },
             {  name: '不良贷款余额',
             
                data: [40, 30, 20, 20, 30,20, 10, 10, 10, 10],
                type: 'bar',
                smooth: 0,
                itemStyle : {  
                    normal : {  
                        lineStyle:{  
                            color:'#d02a46'  
                        }  
                    }  
                },
               
                
            }
            
        
        ]
      })
    }
  }
}
</script>
